from typing import List

# 用时：30% 内存：40%
class Solution:

    def maxScore(self, cardPoints: List[int], k: int) -> int:
        m = len(cardPoints) - k
        flag = sum(cardPoints[0:m])
        sums = sum(cardPoints[0:m])
        for i in range(1, len(cardPoints)-m+1):
            sums = sums + cardPoints[i+m-1] - cardPoints[i-1]
            flag = min(sums, flag)
        return sum(cardPoints) - flag


model = Solution()
cardPoints = [11,49,100,20,86,29,72]
k = 4
print(model.maxScore(cardPoints, k))

cardPoints = [1,2,3,4,5,6,1]
k = 3
print(model.maxScore(cardPoints, k))

cardPoints = [2,2,2]
k = 2
print(model.maxScore(cardPoints, k))

cardPoints = [9,7,7,9,7,7,9]
k = 7
print(model.maxScore(cardPoints, k))

cardPoints = [1,1000,1]
k = 1
print(model.maxScore(cardPoints, k))

cardPoints = [1,79,80,1,1,1,200,1]
k = 3
print(model.maxScore(cardPoints, k))